package com.miya.demo.support.netty;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 信息编码处理器
 *
 * @author CaiXiaowei
 * @date 2023/1/16
 */
public class MessageEncodeHandler extends MessageToByteEncoder<MessageBean> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, MessageBean messageBean, ByteBuf byteBuf) throws Exception {
        byteBuf.writeInt(messageBean.getLen());
        byteBuf.writeBytes(messageBean.getContent());
    }
}
